package top.xchch.xml;

import java.util.Arrays;

import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import top.xchch.xml.service.BookShopService;
import top.xchch.xml.service.Cashier;

class SpringTransactionTest {
	
	private ApplicationContext context;
	private BookShopDao bookShopDao;
	private BookShopService bookShopService;
	private Cashier cashier;
	
	{
		context = new ClassPathXmlApplicationContext("applicationcontext-tx-xml.xml");
		bookShopDao = (BookShopDao) context.getBean("bookShopDao");
		bookShopService = (BookShopService) context.getBean("bookShopService");
		cashier = (Cashier) context.getBean("cashier");
	}
	
	
	@Test
	public void testTransationalPropagation() {
		cashier.checkout("TOM", Arrays.asList("1001", "1003"));
	}
	
	
	@Test
	public void testBookShopService() {
		bookShopService.purchase("JACK", "1001");
	}

}
